'use strict';

/* service */
define(['angular'], function(){
	var comm = angular.module('CommServices', []);
	
	comm.factory('ztree', function(){
		
		var zTree;
		return {
			init : function(params){
				require(['ztree_core'], function(){
					var setting = {
							view: {
								showIcon :false
							},
							data: {
								simpleData: {
									enable: true
								}
							}
						};
					zTree = $.fn.zTree.init($("#"+params.id), setting, angular.fromJson(params.data));
				});
			},
			getSelectNodeId: function(){
				if(zTree){
					var nodes = zTree.getSelectedNodes();
					if(nodes.length <= 0){
						nodes = zTree.getNodes();
					}
					return nodes[0].id;
				}
				return 0;
			}
		};
	});
});
